package com.yuchen.ishop.goods;

import com.alibaba.dubbo.rpc.protocol.rest.support.ContentType;
import com.yuchen.core.jdbc.BaseDao;
import com.yuchen.ishop.entity.GoodsHouse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 */
@Transactional
@Path("goodsHouseService")
@Consumes({MediaType.APPLICATION_JSON, MediaType.TEXT_XML})
@Produces({ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
public class GoodsHouseServiceImpl implements GoodsHouseService{

    @Autowired
    private BaseDao dao;

    @GET
    @Path("get/{id}")
    @Transactional(readOnly = true)
    public GoodsHouse get(@PathParam("id")Long id) {
        return dao.fetch(GoodsHouse.class, id);
    }

    @POST
    @Path("findXiaoqu")
    @Transactional(readOnly = true)
    public List findXiaoqu(String keyword){
        String sql = "select distinct community_name from t_goods_houses where community_name like concat('%',@keyword, '%') limit 50";
        Map param = new HashMap(1);
        param.put("keyword",keyword);
        return dao.querySql(sql.toString(), param);
    }
}
